package com.example.football.controller;

import com.example.football.pojo.People;
import com.example.football.pojo.Peopleliketeam;
import com.example.football.service.PeopleService;
import com.example.football.service.PeopleliketeamService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class PeopleliketeamController {
    @Resource
    private PeopleliketeamService cc;

    //全查
    @RequestMapping("peopleliketeamlist")
    public String queryAll(Model model) {
        List<Peopleliketeam> list = cc.queryAll();
        //存入model
        model.addAttribute("list", list);
        //控制跳转

        return "peopleliketeamlist";
    }

    @RequestMapping("removeByPeopleliketeamid")
    public String removeByPeopleliketeamid(Integer id) {
        try {
            cc.removeByPeopleliketeamid(id);
            return "redirect:/peopleliketeamlist";
        } catch (Exception e) {
            return "error";
        }
    }

    @PostMapping("findByLiketeam")
    public String findByLiketeam(String liketeam, Model model){
        List<Peopleliketeam> list = cc.queryByLiketeam(liketeam);
        //存入model
        model.addAttribute("list", list);
        return "peopleliketeamlist";
    }



    @RequestMapping("addPeopleliketeamPage")
    public String addPeopleliketeamPage() {
        return "addpeopleliketeam";
    }

    @RequestMapping("addPeopleliketeam")
    public String addPeopleliketeam(Peopleliketeam peopleliketeam) {
        try {
            cc.addPeopleliketeam(peopleliketeam);
            return "redirect:/peopleliketeamlist";
        } catch (Exception e) {
            e.printStackTrace();
            return "error";
        }
    }



    @GetMapping("findById3")
    public String findById(Integer id, Model model){
        Peopleliketeam list = cc.queryById(id);
        //存入model
        model.addAttribute("list", list);
        return "updatepeopleliketeam";
    }

    //数据修改
    @PostMapping("updatePeopleliketeam")
    public String changePeopleliketeam(Peopleliketeam peopleliketeam) {
        try {
            cc.changePeopleliketeam(peopleliketeam);
            return "redirect:/peopleliketeamlist";
        } catch (Exception e) {
            return "error";
        }
    }
}
